package edu.uade.clase5;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    public void consultar(View view){
    	
    }
    
    private String obtenerData(){
    	HttpClient client = new DefaultHttpClient();
    	HttpPost post = new HttpPost("http://wap.cotizacion-dolar.com.ar/cotizacion-dolar-hoy.wml");
    	HttpResponse response;
    	try {
			response = client.execute(post);
			if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
				 InputStream is = response.getEntity().getContent();
				 int b;
		    	 StringBuffer sb = new StringBuffer();
				 while ((b = is.read()) != -1){
					 sb.append((char)b);
				 }
				 return sb.toString();
			}else {
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
    }
    
    private String parsearData(String html){
    	String cotizacion = null;
    	String regex = "<small>(.*?)</small><span(.*?)>(.*?)</span>";
    	
    	return cotizacion;
    }

}